package com.googlecode.chigs.web.admin;

import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.target.basic.RedirectRequestTarget;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.googlecode.chigs.domain.ConfigLocation;
import com.googlecode.chigs.domain.ConfigLocationGroup;
import com.googlecode.chigs.domain.Product;
import com.googlecode.chigs.domain.Variant;
import com.googlecode.chigs.domain.Version;
import com.googlecode.chigscommons.domain.User;
import com.googlecode.chigscommons.repository.GenericDomainService;
import com.googlecode.chigscommons.web.WicketWebSession;
import com.googlecode.chigscommons.web.common.IconFactory;

/**
 * @author the
 */
@AuthorizeInstantiation("ROLE_ADMIN")
public class AdminStatisticsPanel extends Panel {
	@SpringBean
	private GenericDomainService genericDomainService;

	public AdminStatisticsPanel(String id) {
		super(id);
		
		Link<Void> userLink = new Link<Void>("users.button") {
			@Override
			public void onClick() {
				getRequestCycle().setRequestTarget(new RedirectRequestTarget(((WicketWebSession) getSession()).getI18nLink("/administration/users.html")));
			}
		};
		userLink.add(new Image("icon", IconFactory.createAddUserIconReference()));
		userLink.add(new Label("users", new Model<Integer>(genericDomainService.getCount(User.class))));
		add(userLink);
		
		Link<Void> productsLink = new Link<Void>("products.button") {
			@Override
			public void onClick() {
				getRequestCycle().setRequestTarget(new RedirectRequestTarget(((WicketWebSession) getSession()).getI18nLink("/administration/products.html")));
			}
		};
		productsLink.add(new Image("icon", IconFactory.createApplicationIconReference()));
		productsLink.add(new Label("products", new Model<Integer>(genericDomainService.getCount(Product.class))));
		add(productsLink);
		
		Link<Void> versionsLink = new Link<Void>("versions.button") {
			@Override
			public void onClick() {
				getRequestCycle().setRequestTarget(new RedirectRequestTarget(((WicketWebSession) getSession()).getI18nLink("/administration/versions.html")));
			}
		};
		versionsLink.add(new Image("icon", IconFactory.createApplicationsIconReference()));
		versionsLink.add(new Label("versions", new Model<Integer>(genericDomainService.getCount(Version.class))));
		add(versionsLink);

		Link<Void> variantsLink = new Link<Void>("variants.button") {
			@Override
			public void onClick() {
				getRequestCycle().setRequestTarget(new RedirectRequestTarget(((WicketWebSession) getSession()).getI18nLink("/administration/variants.html")));
			}
		};
		variantsLink.add(new Image("icon", IconFactory.createApplicationsIconReference()));
		variantsLink.add(new Label("variants", new Model<Integer>(genericDomainService.getCount(Variant.class))));
		add(variantsLink);

		Link<Void> confLocLink = new Link<Void>("configlocations.button") {
			@Override
			public void onClick() {
				getRequestCycle().setRequestTarget(new RedirectRequestTarget(((WicketWebSession) getSession()).getI18nLink("/administration/configlocations.html")));
			}
		};
		confLocLink.add(new Image("icon", IconFactory.createDocumentIconReference()));
		confLocLink.add(new Label("configlocations", new Model<Integer>(genericDomainService.getCount(ConfigLocation.class))));
		add(confLocLink);
		
		Link<Void> confLocGrpLink = new Link<Void>("configlocationgroups.button") {
			@Override
			public void onClick() {
				getRequestCycle().setRequestTarget(new RedirectRequestTarget(((WicketWebSession) getSession()).getI18nLink("/administration/configlocationgroups.html")));
			}
		};
		confLocGrpLink.add(new Image("icon", IconFactory.createDocumentsIconReference()));
		confLocGrpLink.add(new Label("configlocationgroups", new Model<Integer>(genericDomainService.getCount(ConfigLocationGroup.class))));
		add(confLocGrpLink);
	}
}

